package contreller

import (
	"SkillTextJD2/Util"
	"github.com/gin-gonic/gin"
)

func AttractionsInquire(c *gin.Context) {
	name := c.PostForm("txt_cName")
	if name == "" {
		c.JSON(400, gin.H{"error": "缺少名称"})
		return
	}

	updateData := map[string]interface{}{
		"Attractions_discounts":     c.PostForm("txt_cDiscounts"),
		"Attraction_transportation": c.PostForm("txt_cTransportation"),
		"Tour_period":               c.PostForm("txt_cPeriod"),
		"Attractions_price":         c.PostForm("txt_cAttractions_price"),
		"Button":                    c.PostForm("txt_cPButton"),
	}

	err := Util.DB().Table("attractions").
		Where("Attractions_Name LIKE ?", "%"+name+"%").
		Updates(updateData).Error
	if err != nil {
		c.JSON(500, gin.H{"error": err.Error()})
		return
	}

	// 更新完成后返回首页或查询结果
	HandlerIndex(c)
}
